/************************
Name : TestCaseTriggerHandler_AC
Created By : knemala
Created Date : Feb 25, 2013
Description : This is a TEST class, to cover CaseTriggerHandler_AC.

************************/
@isTest
private class TestCaseTriggerHandler_AC {
    
    static testMethod void checkCaseTypeValidateDetailsTest(){
     						  
       Case testCase = TestDatabaseCMS.createCaseForTesting();  
        //Check if the case is inserted correctly                        
        System.assert(testCase != null);
        	
        //Check if the Queue is updated correctly
        System.assertEquals('CM - Queue 19', testCase.Queue_Name__c);
        
        //Check if the Priority is updated correctly
       	System.assertEquals('1', testCase.Priority);
       
		//Check if the Case Group is updated correctly
		System.assertEquals('Administration', testCase.Group__c); 
		
		//Check if the Case Category is updated correctly
		System.assertEquals('Academic', testCase.Category__c);
		
		//Check if the Case Activity is updated correctly
		System.assertEquals('Program', testCase.Activity__c);    
    }
    
    static testMethod void checkCmsDetailsResearch(){
     //Fetch the record type ID
     String cmsRecordTypeId = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('CMS').getRecordTypeId();
    
    DateTime researchDate;
    //Create a test case and insert it		
     Case newCmsCase = new Case(Status='New', RecordTypeId = cmsRecordTypeId, Description = 'Test CMS test' );	
     insert newCmsCase;
     
     System.debug('New Case is' +newCmsCase);
     System.debug('Status is' +newCmsCase.Status);
     System.debug('Status is' +newCmsCase.Status_Pending_Date__c);
     System.debug('Status is' +newCmsCase.Status_Research_Date__c);
     System.debug('Status is' +newCmsCase.Status_Resolution_Date__c);
     //Update the Status of existing case
     newCmsCase.Status = 'Pending Acceptance';
   //  newCmsCase.Status_Research_Date__c  = System.now();
    // researchDate = System.now();
     
    update newCmsCase;
     
     System.debug('Inserted Case' +newCmsCase.Case_RecordTypeName__c);
     //Fetch the updated record
     Case insertedCmsCase = [Select CaseNumber, Status, Status_Pending_Date__c, Status_Research_Date__c, Status_Resolution_Date__c From Case
     							WHERE Id =: newCmsCase.Id ];
     
     System.debug('Updated Case is' +insertedCmsCase);
     System.debug('Status is' +insertedCmsCase.Status);
     System.debug('Status is' +insertedCmsCase.Status_Pending_Date__c);
     System.debug('Status is' +insertedCmsCase.Status_Research_Date__c);
     System.debug('Status is' +insertedCmsCase.Status_Resolution_Date__c);
     //Check if the status is updated correctly
     System.assertEquals(insertedCmsCase.Status, 'Research');	
     
     //Check if the Status Pending Date is being updated						
     System.assertEquals(insertedCmsCase.Status_Pending_Date__c, null);
     
     //Check if the Status Research Date is updated correctly
    System.assertEquals(insertedCmsCase.Status_Research_Date__c, System.now());
     
     //Check if the Status Resolution Date is being updated
     System.assertEquals(insertedCmsCase.Status_Resolution_Date__c, null);
    } 
    
    static testMethod void checkCmsDetailsResolution(){
     //Fetch the record type ID
     String cmsRecordTypeId = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('CMS').getRecordTypeId();
    		
    // Create a new CMS test case and insert it
     Case newCmsCase = new Case(Status='New', RecordTypeId = cmsRecordTypeId, Description = 'Test CMS test' );	
     insert newCmsCase;
     // Update the status to 'Resolution'
     newCmsCase.Status = 'Resolution';
     update newCmsCase;
     //Fetch the updated case
     Case insertedCmsCase = [Select CaseNumber, Status, Status_Pending_Date__c, Status_Research_Date__c, Status_Resolution_Date__c From Case
     							WHERE Id =: newCmsCase.Id ];
     //Check if the status is updated correctly
     System.assertEquals(insertedCmsCase.Status, 'Resolution');	
     
     //Check if the Status Pending Date is being updated					
     System.assertEquals(insertedCmsCase.Status_Pending_Date__c, null);
     
     //Check if the Status Research Date is being updated
     System.assertEquals(insertedCmsCase.Status_Research_Date__c, null);
     
     //Check if the Status Resolution Date is updated correctly
     System.assertEquals((insertedCmsCase.Status_Resolution_Date__c).isSameDay(System.now()), true);
    	
    } 
    
    static testMethod void checkCaseTypeUpdateOwnerIdTest(){
        Case testStatus = TestDatabaseCMS.caseStatusTesting();  
        //Check if the case is inserted correctly                        
        System.assert(testStatus != null); 						  
        //Check if the Case Owner is updated correctly
        System.assertEquals('CM - Queue 19', testStatus.Queue_Name__c); 	
        			  
    }
    static testMethod void checkInitialResponseTest(){
    /* String westSupportRecordTypeId = Schema.Sobjecttype.Case.getRecordTypeInfosByName().get('West - Support').getRecordTypeId();	
     // This test method is used to test the if the Case is updated with the appropriate values
     Case newCaseInitialResponse = new Case(RecordTypeId = westSupportRecordTypeId, Status = 'New',  Case_Name__c = '12 no activity',
        Subject = 'Need help -No activity for 12 days', Description = 'Need help -No activity for 12 days', Origin = 'Phone');
    
        insert newCaseInitialResponse;
        newCaseInitialResponse.Manual_status_change__c = true;
    	newCaseInitialResponse.Status= 'Closed';	
    	update newCaseInitialResponse;
    
    //Fetch the case that has been created above
        Case insertedCaseResponse = [SELECT Queue_Name__c, CaseNumber,Initial_Response_Template_Body__c, Priority, Group__c, Category__c, Activity__c FROM Case
         						  WHERE Id = :newCaseInitialResponse.Id ];
         	
       //  insertedCaseResponse.Initial_Response_Template_Body__c = ''	
       System.debug('my' +insertedCaseResponse.Initial_Response_Template_Body__c);*/
       
       Case insertedCaseResponse = TestDatabaseCMS.caseAutoInitialTesting(); 
       System.debug('Inserted auto response case is'+insertedCaseResponse);
       System.assertEquals('A new case has been created in reference with "Need help -No activity for 12 days". Please contact support to know status of the case or for any additional questions.' , insertedCaseResponse.Initial_Response_Template_Body__c);
    	
    }
    static testMethod void checkCaseTypeValidateUpdationTest(){

         Case insertedCase = TestDatabaseCMS.updateCaseForTesting();  
        //Check if the case is inserted correctly                        
        System.assert(insertedCase != null);
        	
        //Check if the Queue is updated correctly
        System.assertEquals('CM - Queue 1', insertedCase.Queue_Name__c);
        
        //Check if the Priority is updated correctly
       	System.assertEquals('1', insertedCase.Priority);
       
		//Check if the Case Group is updated correctly
		System.assertEquals('Student', insertedCase.Group__c); 
		
		//Check if the Case Category is updated correctly
		System.assertEquals('General', insertedCase.Category__c);
		
		//Check if the Case Activity is updated correctly
		System.assertEquals('Miscellaneous', insertedCase.Activity__c);    
    }
    
}